home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 702 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. From: "Paul D. DeRocco" <pderocco@ix.netcom.com>
  2. Message-ID: <31470289.5AFA@ix.netcom.com>
  3. X-Original-Date: Wed, 13 Mar 1996 12:14:49 -0500
  4. Path: in2.uu.net!bounce-back
  5. Date: 13 Mar 96 23:44:55 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: stack variables and new constructor
  9. Organization: Netcom
  10. References: <Do7nuy.HsF@ncrcae.ColumbiaSC.ATTGIS.COM>
  11. X-Netcom-Date: Wed Mar 13  9:16:00 AM PST 1996
  12. X-Mailer: Mozilla 2.0 (Win95; I)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMUdeBOEDnX0m9pzZAQEXswF+Kdn3YHowyLnMZomFSqsSYdzPIbthjsgQ
  15.     XDos2AXs67dXisKbA63LY7Pfn1HnHTpJ
  16.     =v5dw
  17.  
  18. Jon.Cassorla wrote:
  19. > 1) For a variable that is declared locally to a function of a 
  20. >    structure
  21. >    type, is the standard new constructor executed to allocated the
  22. >    memory for the data structure?
  23.  
  24. No. You mustn't confuse "new" with "constructor". "new" allocates memory 
  25. from the heap (and "delete" returns it). A constructor turns raw memory 
  26. into a valid object (and a destructor turns it back into raw memory). 
  27. Using "new" always calls a constructor if there is one (and "delete" 
  28. always calls a destructor if there is one), but the opposite isn't true. 
  29. If an object is static, it is allocated space by the 
  30. compiler/linker/loader, constructed at the start of the program, and 
  31. destroyed at the end. If an object is dynamic, it is allocated space on 
  32. the stack, constructed when its declaration is executed, and destroyed 
  33. when the containing block exits. Only if it is created in the heap with 
  34. "new" does "operator new" get called.
  35.  
  36. > 2) When using "new" to allocate data space for a variable of a 
  37. >    structure
  38. >    type (ie no constructor defined), is the resulting memory space 
  39. >    zero'd
  40. >    out as a standard?
  41.  
  42. Nope, although there may be OSes that do this.
  43.  
  44. -- 
  45.  
  46. Ciao,
  47. Paul D. DeRocco
  48. ---
  49. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  50. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  51. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  52. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  53. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  54.